<?php


// ==================== Lang Utils =========================

class PhpFaces_Lang_ListObject implements ArrayAccess {
	private $list;
	
	/**
	 * COPIES $list, if specified... otherwise creates new
	 */
	public function __construct( $list = null ) {
		if( $list == null ) {
			$list = array();
		} else if ( $list instanceof PhpFaces_Lang_ListObject ) {
			$list = $list->asArray();
		} else if( !is_array( $list )  ){
			throw new Exception( "TypeMismatch" );
		}
		
		$this->list = $list;
	}
	
	public function add( $item ) {
		array_push( $this->list, $item );
	}
	
	public function remove( $index ) {
		array_splice( $this->list, $index, 1 );
	}
	
	public function asArray() {
		return $this->list;
	}

	// =============== ArrayAccess Implementation =================
	public function offsetExists( $offset ) {
		return array_key_exists( $offset, $this->list );
	}
	
	public function offsetGet( $offset ) {
		return $this->list[ $offset ];
	}
	
	public function offsetSet( $offset, $value ) {
		$this->list[ $offset ] = $value;
	}
	
	public function offsetUnset( $offset ) {
		array_splice( $this->list, $offset, 1 );
	}
	
	public function getSize() {
		return count( $this->list );
	}
}

class PhpFaces_Lang_MapObject implements ArrayAccess {
	private $map;
	
	public function __construct( $map = null ) {
		
		if( $map == null ) {
			$map = array();
		} else if( $map instanceof PhpFaces_Lang_MapObject ) {
			$map = $map->asAssoc();
		} else if( !is_array( $map )  ){
			throw new Exception( "TypeMismatch" );
		}
		$this->map = $map;
	}
	
	public function put( $key, $value ) {
		$this->map[ $key ] = $value;
	}
	
	public function get( $key ) {
		return $this->map[ $key ];
	}
	
	public function remove( $key ) {
		unset( $this->map[ $key ] );
	}
	
	public function keys() {
		return new PhpFaces_Lang_ListObject( array_keys( $this->map ) );
	}
	
	public function values() {
		return new PhpFaces_Lang_ListObject( array_values( $this->map ) );
	}
	
	public function asAssoc() {
		return $this->map;
	}
	
	public function getSize() {
		return count( $this->map );
	}
	
	// =============== ArrayAccess Implementation =================
	public function offsetExists( $offset ) {
		return array_key_exists( $offset, $this->map );
	}
	
	public function offsetGet( $offset ) {
		return $this->map[ $offset ];
	}
	
	public function offsetSet( $offset, $value ) {
		$this->map[ $offset ] = $value;
	}
	
	public function offsetUnset( $offset ) {
		unset( $this->map[ $offset ] );
	}
}




?>